package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.domain.RepPro;
import com.ruoyi.system.utils.ExcelImp;
import com.ruoyi.system.utils.Print;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RepBase;
import com.ruoyi.system.service.IRepBaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报基本信息Controller
 * 
 * @author renfx
 * @date 2021-09-09
 */
@RestController
@RequestMapping("/system/repBase")
public class RepBaseController extends BaseController
{
    @Autowired
    private IRepBaseService repBaseService;

    /**
     * 查询报基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:repBase:list')")
    @GetMapping("/list")
    public TableDataInfo list(RepBase repBase)
    {
        startPage();
        List<RepBase> list = repBaseService.selectRepBaseList(repBase);
        return getDataTable(list);
    }

    /**
     * 导出报基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:repBase:export')")
    @Log(title = "报基本信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export/{id}")
    public AjaxResult export(@PathVariable("id") Integer id)
    {
        RepBase repBase = new RepBase();
        repBase.setId(id);
        List<RepBase> list = repBaseService.selectRepBaseList(repBase);
        ExcelUtil<RepBase> util = new ExcelUtil<RepBase>(RepBase.class);
        return ExcelImp.print(list,repBaseService);

//        return util.exportExcel(list, "报基本信息数据");
    }

    /**
     * 获取报基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:repBase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(repBaseService.selectRepBaseById(id));
    }

    /**
     * 新增报基本信息
     */
    @PreAuthorize("@ss.hasPermi('system:repBase:add')")
    @Log(title = "报基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RepBase repBase)
    {
        return toAjax(repBaseService.insertRepBase(repBase));
    }

    /**
     * 修改报基本信息
     */
    @PreAuthorize("@ss.hasPermi('system:repBase:edit')")
    @Log(title = "报基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RepBase repBase)
    {
        return toAjax(repBaseService.updateRepBase(repBase));
    }

    /**
     * 删除报基本信息
     */
    @PreAuthorize("@ss.hasPermi('system:repBase:remove')")
    @Log(title = "报基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(repBaseService.deleteRepBaseByIds(ids));
    }

    /**
     * 获取报分类汇总信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:repPro:showrep')")
    @GetMapping("/geRepBase/{id}")
    public TableDataInfo geRepBase(@PathVariable("id") Integer id)
    {
        startPage();
        List<RepPro> list = repBaseService.selectDetail(id);
        return getDataTable(list);
    }
}
